import * as TYPES from "@/constants/index";
import * as UTILS from "@/utils/index";

import api from "@/api/index";
import { Toast } from "vant";

const state = {
  deviceId: "",
  deviceType: "",
  deviceImg: "",
  machineUrl: "",
  wechatLoginUrl: "",
  downloadUrl: "",
  name: "",
  socket: {
    //wechat/login 登录后获取的socket地址数据
    did: "",
    mac: "",
    msg: "",
    online: false,
    protocolType: 0,
    ret: "",
    uid: "",
    ws_path: "",
  },
};

const mutations = {
  [TYPES.UPDATE_DEVICE_STATE]: (state, payload) => {
    const { key, value } = payload;
    if (state.hasOwnProperty(key)) state[key] = value;
  },
  [TYPES.CHANGE_DEVICE_ID]: (state, payload) => {
    state.deviceId = payload;
  },
  [TYPES.CHANGE_DEVICE_TYPE]: (state, payload) => {
    state.deviceType = payload;
  },
  [TYPES.CHANGE_DEVICE_IMG]: (state, payload) => {
    state.deviceImg = payload;
  },
  [TYPES.CHANGE_DEVICE_MACHINEURL]: (state, payload) => {
    state.machineUrl = payload;
  },
  [TYPES.UPDATE_DEVICE_SOCKET_DATA]: (state, payload) => {
    
    state.socket = payload;
  },
  
};

const actions = {
  //获取用户关联宝宝信息
  // test: async ({ commit }, payload) => {
  //   try {
  //   } catch (err) {
  //     console.log(err);
  //     Toast.fail(err.message);
  //   }
  // },

  // async updateDeviceStatus ({ commit}, payload) { 
  //   commit();
  // }
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
};
